#-*- coding:utf-8 -*-
#作用：学习复杂html解析,fand()和fandAll()
#作者：王珅
#日期：2017年11月24日
#邮箱：ws1992jx@163.com

from urllib.request import urlopen
from bs4 import BeautifulSoup
import time

html=urlopen(' http://www.pythonscraping.com/pages/warandpeace.html')
bsObj=BeautifulSoup(html)

#利用fandAll查找span标签，class:grean的内容
nameList=bsObj.findAll("span",{"class":"green"})

#manname=open('F:/jobdir/Python3/name.txt','a')

for name in nameList:
	#get_text()摘除标签显示标签内的内容
	print (name.get_text())
	#manname.write(name.get_text()+'\n')
	

nameList_1=bsObj.findAll(text='the prince')
print (len(nameList_1))

p=bsObj.findAll('span',{'class':'red'})
for pfile in p:
	print (pfile.get_text())